// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
// 云函数入口函数
// 通过openid获取订单信息
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let openid = wxContext.OPENID;
  let status = event.status || 0;
  let result = await db.collection("order").where({
    openid,
    status:status
  }).get();
  let list = result.data;
  let totalPrice = 0;
  list.forEach(el=>{
    totalPrice += el.goods.price*100
  });
  totalPrice = totalPrice / 100;
  return {
    event,
    openid,
    data:result.data,
    totalPrice
  }
}